﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Resources;

public partial class PageWithAccordion : System.Web.UI.Page
{
    public string TrendWord { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {

        foreach (string key in Request.QueryString)
        {
            switch (key.ToLower())
            {
                case "trendex": this.TrendWord = Request.QueryString[key]; break;
            }
        }
        if (!string.IsNullOrEmpty(this.TrendWord))
        {
            bool PageAllowed = GoogleHelper.CheckKeyWordAllowed(this.TrendWord);
            if (!PageAllowed)
            {
                Response.Redirect("default.aspx");
                Response.Write("this query is not allowed on this page");
            }
        }


        if (!IsPostBack)
        {



            if (string.IsNullOrEmpty(this.TrendWord) || this.TrendWord.ToLower().Contains("buzzminute.com"))
            {
                this.TrendWord = "Breaking News";
            }
            //show news from google        
            GoogleNewsDataSource.DataFile = string.Format(GoogleHelper.GoogleNewsFeedUrl, TrendWord);
            GoogleNewsListView.DataSourceID = GoogleNewsDataSource.UniqueID;
            GoogleNewsListView.DataBind();

            //show blogsearch
            BlogSearchDataSource.DataFile = string.Format(GoogleHelper.BlogSearchFeedUrl, TrendWord);
            BlogSearchListView.DataSourceID = BlogSearchDataSource.UniqueID;
            BlogSearchListView.DataBind();
        }
    }
    protected void GoogleNewsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
    {

    }
    protected void GoogleNewsListView_ItemCreated(object sender, ListViewItemEventArgs e)
    {

    }
    protected void GoogleNewsListView_DataBound(object sender, EventArgs e)
    {
        if (GoogleNewsListView.Items != null && GoogleNewsListView.Items.Count > 0)
        {
            foreach (ListViewItem item in GoogleNewsListView.Items)
            {
                Label adsenseLabel = item.FindControl("AdsenseInlineLabel") as Label;
                adsenseLabel.Text = ComplexStrings.Adsense336x280;
                adsenseLabel.Visible = true;
            }
        }
    }
}

